package com.movieproject.src;

import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.movieproject.daos.QueueDAO;
import com.movieproject.daos.ReviewDAO;
import com.movieproject.dataobjects.Movie;
import com.movieproject.dataobjects.Queue;
import com.movieproject.dataobjects.Review;

@Controller
@RequestMapping(value = "/movie")
public class AddtoQueue {

	@RequestMapping(method = RequestMethod.GET)

	public String addtoQueue(Map<String, Object> model) {
		Queue queueForm = new Queue(); 
		model.put("queueForm", queueForm);

		//name of jsp file
		return "movie";
	}



	@RequestMapping(method = RequestMethod.POST)
	public String processQueue(@ModelAttribute("queueForm") Queue queue,
			Map<String, Object> model) {

		ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");

		QueueDAO queueDAO = (QueueDAO) context.getBean("queueDAO");
		
		int a = queue.getMovieID();
		int b = queue.getUserID();
		int c = queue.getPosition();
		


		Queue q = new Queue(a,b,c);
		queueDAO.insert(q);
		
		
		
		return "viewqueue";
	}

	
	
}
